<?php
class GspController extends Controller{
  public $isActivated = 0;
          public function accessRules()
		 {
			return array(
			   array(
					'allow',  // allow all users to access 'index' and 'view' actions.
					'expression'=>'$user->rights>=2',
				),
				array(
					'deny',  // deny all users
					'users'=>array('*'),
					'message'=>'You do not have access to this page ! ! ',
				),
				
			);
		 } 
     public function actionAddgsp(){
		  $this->breadcrumbs=array(
               'GSP和综合素质'=>array('addgsp'),
               '添加GSP条目',
             );
	      if(Yii::app()->request->requestType == "POST"){
			   $this->addGspDeal();	
		  } 
		 
		  $ci = new CDbCriteria;
		  $total = Gspitem::model()->count($ci);
		  $pages =  new CPagination($total);
		  $pages->pageSize = 40;
		  $pages->applyLimit($ci);
		  $gspItems  = Gspitem::model()->findAll($ci);
		  
		 $this->render("addgsp",array('gspItems'=>$gspItems,'pages'=>$pages));
		 
	 }
	 protected function addGspDeal(){
		 $_POST['addtime'] = date('Y-m-d H:i:s');
		 $gsp = new Gspitem;
		 $gsp->attributes  = $_POST;
		 if($gsp->save()){
		    Yii::app()->user->setFlash('add','添加成功');	 
		 }else{
			 Yii::app()->user->setFlash('add','添加失败');
	     }
		 $this->redirect(array('gsp/addgsp'));
	 }
	 public function actionDeletegsp(){
		 if(Yii::app()->request->isAjaxRequest){
			 $id = $_POST['gspId'];
			 $gsp = Gspitem::model()->findByPk($id);
			 if($gsp){
				 if($gsp->delete()){
					 echo json_encode(array('code'=>200,'msg'=>'删除成功')); 
				 }else{
					 $this->logAr($gsp);
					 echo json_encode(array('code'=>501,'msg'=>'删除失败')); 
				 }
			 }else{
				 
				 echo json_encode(array('code'=>404,'msg'=>'没有找到这个条目')); 
			 }
		 }else{
			 echo '非法的操作';
			 
		 }
		 
	 }
	 public function actionAddintegration(){
		  $this->breadcrumbs=array(
               'GSP和综合素质'=>array('addgsp'),
               '添加综合素质条目',
             );
		 if(Yii::app()->request->requestType == 'POST'){
			 
			 $this->addInteDeal();
		 }
		  $ci = new CDbCriteria;
		  $total = Inteitem::model()->count($ci);
		  $pages =  new CPagination($total);
		  $pages->pageSize = 40;
		  $pages->applyLimit($ci);
		  $intes = Inteitem::model()->findAll($ci);
		 $this->render("addintegration",array('intes'=>$intes,'pages'=>$pages));
		 
	 }
	 protected function  addInteDeal(){
		 
		 $inte =  new Inteitem;
		 $_POST['addtime'] = date('Y-m-d H:i:s');
		 $inte->attributes = $_POST;
		 if($inte->save()){
			Yii::app()->user->setFlash('add','添加成功'); 
		  }else{
			  $this->logAr($inte);
			 Yii::app()->user->setFlash('add','添加失败'); 
		 }
		 $this->redirect(array('gsp/addintegration'));
	 }
	 public function actionDeleteinte(){
		 if(Yii::app()->request->isAjaxRequest){
			 $id = $_POST['inteId'];
			 $gsp = Inteitem::model()->findByPk($id);
			 if($gsp){
				 if($gsp->delete()){
					 echo json_encode(array('code'=>200,'msg'=>'删除成功')); 
				 }else{
					 $this->logAr($gsp);
					 echo json_encode(array('code'=>501,'msg'=>'删除失败')); 
				 }
			 }else{
				 
				 echo json_encode(array('code'=>404,'msg'=>'没有找到这个条目')); 
			 }
		 }else{
			 echo '非法的操作';
			 
		 }
		 
	 }
	 
	 public function actionCheckinte(){
		 $this->breadcrumbs=array(
               'GSP和综合素质'=>array('addgsp'),
               '审核GSP',
             );
	      $classRooms  = Classroom::model()->findAll();
		  $ci  = new CDbCriteria();
		  $major = Major::model()->findAll();
		 if(!empty($_GET) && (count($_GET) >= 4)){
		  foreach($_GET as $key => $value){
			  if($value == '' || $key == 'page')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('u.username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('u','stuinfo');
		 }
		 
		 $ci->addCondition('t.condition = 1');
		 
		 $total = Stuinteitem::model()->count($ci);
		 $pages =  new CPagination($total);
		 $pages->pageSize = 20;
		 $pages->applyLimit($ci);
		 $stuIntes  = Stuinteitem::model()->findAll($ci);
		 $this->render("checkinte",array('major'=>$major,'classRooms'=>$classRooms,'stuIntes'=>$stuIntes,'pages'=>$pages,'total'=>$total));
		 
		 
	 }
	  public function actionAddintecomment(){
		   if(Yii::app()->request->isAjaxRequest){
			   $stuInte  = Stuinteitem::model()->findByPk($_POST['stuInteItemId']);
			   $comment = $_POST['comment'];
			   if($stuInte){
			   $stuN = new Stunotification;
			   $stuN->uId = $stuInte->uId;
			   $stuN->detailId = $stuInte->stuInteItemId;
			   $stuN->module = 4; //1 -- 个人信息 2 -- 综合奖学金 3 -- GSP 4---综合素质 5 -- 学生报名
			   $stuN->comment = $comment;
			   $stuN->addtime = date('Y-m-d H:i:s');
			   $stuN->isRead = 0;
			   $stuInte->condition = 2 ;// 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
			   if($stuN->save()&&$stuInte->save()){
				  
				  echo  json_encode(array('code'=>200,'msg'=>'添加成功'));
			   }else{
					$this->logAr($stuN);
					$this->logAr($stuInte);
					echo  json_encode(array('code'=>502,'msg'=>'添加失败'));
				}
			   
			   
			   }else{
				  
				  echo  json_encode(array('code'=>404,'msg'=>'没有找到条目'));
				   
			   }
		   }else{
			   $this->redirect(array('gsp/checkinte'));
			   
		   }
		   
	   }
	  public function actionPassinteone(){
		 if(Yii::app()->request->isAjaxRequest){
			   $stuInteItem = Stuinteitem::model()->findByPk(Yii::app()->request->getParam('stuInteItemId'));
			   if($stuInteItem){
				   $stuInteItem->condition = 3 ; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuInteItem->save()){
						
						echo  json_encode(array('code'=>200,'msg'=>' 审核成功'));
						
				   }else{
					   $this->logAr($stuInteItem);
					   echo  json_encode(array('code'=>502,'msg'=>'审核失败'));
				   }
			   }else{
				   echo  json_encode(array('code'=>404,'msg'=>'审核失败，没有找到这个条目'));
				   
			   }
			   
		   }else{
			   $this->logError('非法请求，inte 审核 ajax');
			   $this->redirect(array('gsp/checkinte'));
			   
		   }
		   
		  
	  }
	   public function actionPassintemuti(){
		   $successNum = 0;
		   $successArray = array();
		   if(Yii::app()->request->isAjaxRequest){
			   $stus = '&'.$_POST['stus'];
			   $stuArray = explode('&l=',$stus);
			  foreach($stuArray as $inteItemId){
				  if($inteItemId == '')
					  continue;
			   $stuInte = Stuinteitem::model()->findByPk($inteItemId);
			   if($stuInte){
				   $stuInte->condition = 3; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuInte->save()){
					    $successArray[$successNum] = $inteItemId;
						$successNum++;
				    }else{
					   $this->logAr($stuInte);
					   echo  json_encode(array('code'=>502,'msg'=>' 审核失败'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
					   return;
				   }
			    }else{
				   echo  json_encode(array('code'=>404,'msg'=>'审核失败，没有找到用户'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
				   return;
			    }
			  }
		   echo  json_encode(array('code'=>200,'msg'=>'审核成功的学生数目：'.$successNum,'successArray'=>$successArray));
		   }else{
			   $this->logError('非法请求, inte 多位 学生审核 ajax');
			   $this->redirect(array('gsp/checkinte'));
			   
		   }
		   
	   }
	   public function actionUnpassintemuti(){
		   $successNum = 0;
		   $successArray = array();
		   if(Yii::app()->request->isAjaxRequest){
			   $stus = '&'.$_POST['stus'];
			   $stuArray = explode('&l=',$stus);
			  foreach($stuArray as $inteItemId){
				  if($inteItemId == '')
					  continue;
			   $stuInte =Stuinteitem::model()->findByPk($inteItemId);
			   if($stuInte){
				   $stuN = new Stunotification;
				   $stuN->uId = $stuInte->uId;
				   $stuN->detailId = $stuInte->stuInteItemId;
				   $stuN->module = 4; //1 -- 个人信息 2 -- 综合奖学金 3 -- GSP 4---综合素质 5 -- 学生报名
				   $stuN->comment = '同学，您的这一条综合素质没有通过审核，请删除后，再次提交';
				   $stuN->addtime = date('Y-m-d H:i:s');
				   $stuN->isRead = 0;
				   
				   $stuInte->condition = 2; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuInte->save()&&$stuN->save()){
					    $successArray[$successNum] = $inteItemId;
						$successNum++;
				    }else{
					   $this->logAr($stuGsp);
					   echo  json_encode(array('code'=>502,'msg'=>' 审核失败'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
					   return;
				   }
			    }else{
				   echo  json_encode(array('code'=>404,'msg'=>'添加不通过审核失败，没有找到用户'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
				   return;
			    }
			  }
		   echo  json_encode(array('code'=>200,'msg'=>'添加不通过审核成功的学生数目：'.$successNum,'successArray'=>$successArray));
		   }else{
			   $this->logError('非法请求，inte 多位 学生审核 ajax');
			   $this->redirect(array('gsp/checkinte'));
			   
		   }
		   
	   }
	   public function actionUpdatestuinte(){
		   if(Yii::app()->request->isAjaxRequest){
			   $stuInteItem  = Stuinteitem::model()->findByPk(Yii::app()->request->getParam('stuInteItemId'));
			   $request = Yii::app()->request;
			   if($stuInteItem){
				   $stuInteItem->detail = $request->getParam('detail');
				   $stuInteItem->credit = $request->getParam('credit');
				   $stuN = new Stunotification;
				   $stuN->uId = $stuInteItem->uId;
				   $stuN->detailId = $stuInteItem->stuInteItemId;
				   $stuN->module = 4; //1 -- 个人信息 2 -- 综合奖学金 3 -- GSP 4---综合素质 5 -- 学生报名
				   $stuN->comment = '同学，您的这一条综合素质经过老师修改之后，通过了审核';
				   $stuN->addtime = date('Y-m-d H:i:s');
				   $stuN->isRead = 0;
				   
				   $stuInteItem->condition = 3; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuInteItem->save()&&$stuN->save()){
					   
					   echo  json_encode(array('code'=>200,'msg'=>'添加成功，并且已给学生添加通知'));
					   
				   }else{
					    $this->logAr($stuInteItem);
						$this->logAr($stuN);
					    echo  json_encode(array('code'=>501,'msg'=>'添加失败'));
				   }
			   }else{
				   
				   echo  json_encode(array('code'=>404,'msg'=>'没有找到这个条目'));
			   }
			   
		   }else{
			   $this->redirect(array('gsp/checkinte'));
		   }
		   
		   
	   }
	 public function actionCheckgsp(){
		  $this->breadcrumbs=array(
               'GSP和综合素质'=>array('addgsp'),
               '审核GSP',
             );
	      $classRooms  = Classroom::model()->findAll();
		  $ci  = new CDbCriteria();
		   $major = Major::model()->findAll();
		 if(!empty($_GET) && (count($_GET) >= 4)){
		  foreach($_GET as $key => $value){
			  if($value == '' || $key == 'page')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('u.username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('u','stuinfo');
		 }
		 
		 $ci->addCondition('t.condition = 1');
		 
		 $total = Stugspitem::model()->count($ci);
		 $pages =  new CPagination($total);
		 $pages->pageSize = 20;
		 $pages->applyLimit($ci);
		 $stuGsps  = Stugspitem::model()->findAll($ci);
		 $this->render("checkgsp",array('major'=>$major,'classRooms'=>$classRooms,'stuGsps'=>$stuGsps,'pages'=>$pages,'total'=>$total));
		 
	 }
	  public function actionAddgspcomment(){
		   if(Yii::app()->request->isAjaxRequest){
			   $stuGsp  = Stugspitem::model()->findByPk($_POST['stuGspItemId']);
			   $comment = $_POST['comment'];
				   if($stuGsp){
				   $stuN = new Stunotification;
				   $stuN->uId = $stuGsp->uId;
				   $stuN->detailId = $stuGsp->stuGspItemId;
				   $stuN->module = 3; //1 -- 个人信息 2 -- 综合奖学金 3 -- GSP 4---综合素质 5 -- 学生报名
				   $stuN->comment = $comment;
				   $stuN->addtime = date('Y-m-d H:i:s');
				   $stuN->isRead = 0;
				   $stuGsp->condition = 2 ;// 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuN->save()&&$stuGsp->save()){
					  
					  echo  json_encode(array('code'=>200,'msg'=>'添加成功'));
				   }else{
						$this->logAr($stuN);
						$this->logAr($stuGsp);
						echo  json_encode(array('code'=>502,'msg'=>'添加失败'));
					}
				   
				   
			   }else{
				   
				  echo  json_encode(array('code'=>404,'msg'=>'没有找到条目'));
				   
			   }
		   }else{
			   $this->logError('非法请求，gsp 学生评论添加 ajax');
			   $this->redirect(array('gsp/checkgsp'));
			   
		   }
		   
	   }
	  public function actionPassgspone(){
		 if(Yii::app()->request->isAjaxRequest){
			   $stuGspItem = Stugspitem::model()->findByPk(Yii::app()->request->getParam('stuGspItemId'));
			   if($stuGspItem){
				   $stuGspItem->condition = 3 ; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuGspItem->save()){
						
						echo  json_encode(array('code'=>200,'msg'=>' 审核成功'));
						
				   }else{
					   $this->logAr($stuGspItem);
					   echo  json_encode(array('code'=>502,'msg'=>'审核失败'));
				   }
			   }else{
				   echo  json_encode(array('code'=>404,'msg'=>'审核失败，没有找到用户'));
				   
			   }
			   
		   }else{
			   $this->logError('非法请求，gsp 审核 ajax');
			   $this->redirect(array('gsp/checkgsp'));
			   
		   }
		   
		  
	  }
	   public function actionPassgspmuti(){
		   $successNum = 0;
		   $successArray = array();
		   if(Yii::app()->request->isAjaxRequest){
			   $stus = '&'.$_POST['stus'];
			   $stuArray = explode('&l=',$stus);
			  foreach($stuArray as $gspItemId){
				  if($gspItemId == '')
					  continue;
			   $stuGsp = Stugspitem::model()->findByPk($gspItemId);
			   if($stuGsp){
				   $stuGsp->condition = 3; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuGsp->save()){
					    $successArray[$successNum] = $gspItemId;
						$successNum++;
				    }else{
					   $this->logAr($stuGsp);
					   echo  json_encode(array('code'=>502,'msg'=>' 审核失败'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
					   return;
				   }
			    }else{
				   echo  json_encode(array('code'=>404,'msg'=>'审核失败，没有找到用户'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
				   return;
			    }
			  }
		   echo  json_encode(array('code'=>200,'msg'=>'审核成功的学生数目：'.$successNum,'successArray'=>$successArray));
		   }else{
			   $this->logError('非法请求，gsp 多位 学生审核 ajax');
			   $this->redirect(array('gsp/checkgsp'));
			   
		   }
		   
	   }
	   public function actionUnpassgspmuti(){
		   $successNum = 0;
		   $successArray = array();
		   if(Yii::app()->request->isAjaxRequest){
			   $stus = '&'.$_POST['stus'];
			   $stuArray = explode('&l=',$stus);
			  foreach($stuArray as $gspItemId){
				  if($gspItemId == '')
					  continue;
			   $stuGsp =Stugspitem::model()->findByPk($gspItemId);
			   if($stuGsp){
				   $stuN = new Stunotification;
				   $stuN->uId = $stuGsp->uId;
				   $stuN->detailId = $stuGsp->stuGspItemId;
				   $stuN->module = 3; //1 -- 个人信息 2 -- 综合奖学金 3 -- GSP 4---综合素质 5 -- 学生报名
				   $stuN->comment = '同学，您的这一条GSP没有通过审核，请删除后，再次提交';
				   $stuN->addtime = date('Y-m-d H:i:s');
				   $stuN->isRead = 0;
				   
				   $stuGsp->condition = 2; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuGsp->save()&&$stuN->save()){
					    $successArray[$successNum] = $gspItemId;
						$successNum++;
				    }else{
					   $this->logAr($stuGsp);
					   echo  json_encode(array('code'=>502,'msg'=>' 审核失败'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
					   return;
				   }
			    }else{
				   echo  json_encode(array('code'=>404,'msg'=>'添加不通过审核失败，没有找到用户'.'<br>成功的学生数目：'.$successNum,'successArray'=>$successArray));
				   return;
			    }
			  }
		   echo  json_encode(array('code'=>200,'msg'=>'添加不通过审核成功的学生数目：'.$successNum,'successArray'=>$successArray));
		   }else{
			   $this->logError('非法请求，gsp 多位 学生审核 ajax');
			   $this->redirect(array('gsp/checkgsp'));
			   
		   }
		   
	   }
	   public function actionUpdatestugsp(){
		   if(Yii::app()->request->isAjaxRequest){
			   $stuGspItem  = Stugspitem::model()->findByPk(Yii::app()->request->getParam('stuGspItemId'));
			   $request = Yii::app()->request;
			   if($stuGspItem){
				   $stuGspItem->detail = $request->getParam('detail');
				   $stuGspItem->credit = $request->getParam('credit');
				   $stuN = new Stunotification;
				   $stuN->uId = $stuGspItem->uId;
				   $stuN->detailId = $stuGspItem->stuGspItemId;
				   $stuN->module = 3; //1 -- 个人信息 2 -- 综合奖学金 3 -- GSP 4---综合素质 5 -- 学生报名
				   $stuN->comment = '同学，您的这一条GSP经过老师修改之后，通过了审核';
				   $stuN->addtime = date('Y-m-d H:i:s');
				   $stuN->isRead = 0;
				   
				   $stuGspItem->condition = 3; // 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				   if($stuGspItem->save()&&$stuN->save()){
					   
					   echo  json_encode(array('code'=>200,'msg'=>'添加成功，并且已给学生添加通知'));
					   
				   }else{
					    $this->logAr($stuGspItem);
						$this->logAr($stuN);
					    echo  json_encode(array('code'=>501,'msg'=>'添加失败'));
				   }
			   }else{
				   
				   echo  json_encode(array('code'=>404,'msg'=>'没有找到这个条目'));
			   }
			   
		   }else{
			   $this->redirect(array('gsp/checkgsp'));
		   }
		   
		   
	   }
	   public function actionIntestulist(){
		 $classRooms  = Classroom::model()->findAll();
		 $this->breadcrumbs=array(
               'GSP和综合素质'=>array('addgsp'),
               '综合素质学生报表',
             );
	     
		  $ci  = new CDbCriteria();
		   $major = Major::model()->findAll();
		 if(!empty($_GET) && (count($_GET) >= 4)){
		  foreach($_GET as $key => $value){
			  if($value == '' || $key == 'page')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('stuinfo');
		 }
		 
		
		 $ci->addCondition('rights = 1');
		 $total = User::model()->count($ci);
		 $pages =  new CPagination($total);
		 $pages->pageSize = 80;
		 $pages->applyLimit($ci);
		 $users  = User::model()->findAll($ci);
		 $this->render("intestulist",array('major'=>$major,'classRooms'=>$classRooms,'pages'=>$pages,'users'=>$users,'total'=>$total));
		 
	 }
	  public function actionGspstulist(){
		 $classRooms  = Classroom::model()->findAll();
		 $this->breadcrumbs=array(
               'GSP和综合素质'=>array('addgsp'),
               'GSP学生报表',
             );
	     
		  $ci  = new CDbCriteria();
		   $major = Major::model()->findAll();
		 if(!empty($_GET) && (count($_GET) >= 4)){
		  foreach($_GET as $key => $value){
			  if($value == '' || $key == 'page')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('stuinfo');
		 }
		 
		
		 $ci->addCondition('rights = 1');
		 $total = User::model()->count($ci);
		 $pages =  new CPagination($total);
		 $pages->pageSize = 80;
		 $pages->applyLimit($ci);
		 $users  = User::model()->findAll($ci);
		
		 
		 $this->render("gspstulist",array('major'=>$major,'classRooms'=>$classRooms,'pages'=>$pages,'users'=>$users,'total'=>$total));
		 
	 }
	  public function actionStugspreport(){
		 $request = Yii::app()->request;
		 $total = 0.0;
		 if(is_numeric($request->getParam('uId'))){
			 $uId = $request->getParam('uId');
			
			 $user = User::model()->find('uId = :u',array(':u'=>$uId));
			 $stuGsps = Stugspitem::model()->findAll('uId = :u',array(':u'=>$uId));
			 foreach($stuGsps as $s){
				 if($s->condition == '3')
				 $total+=(float)$s->credit;
				 
			 }
			 
		 }else{
			 $this->redirect('gsp/gspstulist');
			 
		 }
		 $this->render("stugsp_r",array('total'=>$total,'user'=>$user,'stuGsps'=>$stuGsps));
		 
	 }
	 public function actionStuintereport(){
		 $request = Yii::app()->request;
		 $total = 0.0;
		 if(is_numeric($request->getParam('uId'))){
			 $uId = $request->getParam('uId');
			 
			 $user = User::model()->find('uId = :u',array(':u'=>$uId));
			 $stuIntes = Stuinteitem::model()->findAll('uId = :u',array(':u'=>$uId));
			 foreach($stuIntes as $s){
				 if($s->condition == '3')
				 $total+=(float)$s->credit;
				 
			 }
			 
		 }else{
			 $this->redirect('gsp/intestulist');
			 
		 }
		 $this->render("stuinte_r",array('total'=>$total,'user'=>$user,'stuIntes'=>$stuIntes));
		 
	 }
	 public function actionExportgspexcel(){
		 
		 $ci  = new CDbCriteria();
		 if(!empty($_GET) && (count($_GET) == 4)){
		  foreach($_GET as $key => $value){
			  if($value == '')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('stuinfo');
		 }
		 $ci->addCondition('rights = 1');
		 $users  = User::model()->findAll($ci);
		  
		  Yii::$enableIncludePath = false;
		  Yii::import('application.extensions.phpExcel.PHPExcel',1);
		  $objPHPExcel = new PHPExcel();
		  $objPHPExcel->getProperties()->setCreator("kezhi Company")
							 ->setLastModifiedBy("第二师范学院学生信息管理系统")
							 ->setTitle(date('Y-m-d H:i:s').'学生GSP导出')
							 ->setSubject("学生信息导出")
							 ->setDescription("学生信息导出")
							 ->setKeywords("学生信息导出")
							 ->setCategory("export gspinfo file");
		 
		  $objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A1', '学号')
					->setCellValue('B1', '姓名')
					->setCellValue('C1', '年级')
					->setCellValue('D1', '班级')
					->setCellValue('E1', '专业')
					->setCellValue('F1', 'G(通识能力)')
					->setCellValue('G1', 'S(学科能力)')
					->setCellValue('H1', 'P(专业能力)')
					->setCellValue('I1', '其他')
					->setCellValue('J1', '合计');
		$i = 2;			
		 foreach($users as $u){
			 $g = 0;
			 $ss = 0;
			 $p = 0;
			 $q = 0;
			 $stuGsps = Stugspitem::model()->findAll('uId = :u',array(':u'=>$u->uId));
			 foreach($stuGsps as $s){
				 if($s->condition == '3'){
				    switch($s->module){
						case 'G':$g+=$s->credit;break;
						case 'S':$ss+=$s->credit;break;
						case 'P':$p+=$s->credit;break;
						case '其他':$q+=$s->credit;break;
						
					}
				 }
			 }
			 if($u->stuinfo){
				     $realName = $u->stuinfo->realName;
					 $grade = $u->stuinfo->grade;
					 $classRoom = $u->stuinfo->classRoom;
					 $major = $u->stuinfo->major; 
				    
			 }else{
				     $realName = '未填写';
					 $grade = '未填写';
					 $classRoom = '未填写';
					 $major = '未填写'; 
				 
			 }
			$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$i, $u->username)
					->setCellValue('B'.$i, $realName)
					->setCellValue('C'.$i, $grade)
					->setCellValue('D'.$i, $classRoom)
					->setCellValue('E'.$i, $major)
					->setCellValue('F'.$i, $g)
					->setCellValue('G'.$i, $ss)
					->setCellValue('H'.$i, $p)
					->setCellValue('I'.$i, $q)
					->setCellValue('J'.$i, $g+$ss+$p+$q);	
					$i++;		
			
		 }			
					
		 $this->downloadExcel(date('Y-m-d').'学生GSP导出',$objPHPExcel);
	 }
	 public function actionExportinteexcel(){
		  $ci  = new CDbCriteria();
		 if(!empty($_GET) && (count($_GET) == 4)){
		  foreach($_GET as $key => $value){
			  if($value == '')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('stuinfo');
		 }
		 $ci->addCondition('rights = 1');
		 $users  = User::model()->findAll($ci);
		  
		  Yii::$enableIncludePath = false;
		  Yii::import('application.extensions.phpExcel.PHPExcel',1);
		  $objPHPExcel = new PHPExcel();
		  $objPHPExcel->getProperties()->setCreator("kezhi Company")
							 ->setLastModifiedBy("第二师范学院学生信息管理系统")
							 ->setTitle(date('Y-m-d H:i:s').'学生综合素质导出')
							 ->setSubject("学生信息导出")
							 ->setDescription("学生信息导出")
							 ->setKeywords("学生信息导出")
							 ->setCategory("export 综合素质 file");
		 
		  $objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A1', '学号')
					->setCellValue('B1', '姓名')
					->setCellValue('C1', '年级')
					->setCellValue('D1', '班级')
					->setCellValue('E1', '专业')
					->setCellValue('F1', '养成教育')
					->setCellValue('G1', '情商培养')
					->setCellValue('H1', '社会实践')
					->setCellValue('I1', '专业应用')
					->setCellValue('J1', '合计');
		$i = 2;			
		 foreach($users as $u){
			 $yc = 0;
			 $qs = 0;
			 $sh = 0;
			 $zy = 0;
			 $stuIntes = Stuinteitem::model()->findAll('uId = :u',array(':u'=>$u->uId));
			 foreach($stuIntes as $s){
				 if($s->condition == '3'){
				    switch($s->module){
						case '养成教育':$yc+=$s->credit;break;
						case '情商培养':$qs+=$s->credit;break;
						case '社会实践':$sh+=$s->credit;break;
						case '专业应用':$zy+=$s->credit;break;
						
					}
				 }
			 }
			 if($u->stuinfo){
				     $realName = $u->stuinfo->realName;
					 $grade = $u->stuinfo->grade;
					 $classRoom = $u->stuinfo->classRoom;
					 $major = $u->stuinfo->major; 
				    
			 }else{
				     $realName = '未填写';
					 $grade = '未填写';
					 $classRoom = '未填写';
					 $major = '未填写'; 
				 
			 }
			$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$i, $u->username)
					->setCellValue('B'.$i, $realName)
					->setCellValue('C'.$i, $grade)
					->setCellValue('D'.$i, $classRoom)
					->setCellValue('E'.$i, $major)
					->setCellValue('F'.$i, $yc)
					->setCellValue('G'.$i, $qs)
					->setCellValue('H'.$i, $sh)
					->setCellValue('I'.$i, $zy)
					->setCellValue('J'.$i, $yc+$qs+$sh+$zy);	
					$i++;		
			
		 }			
					
		 $this->downloadExcel(date('Y-m-d').'学生综合素质导出',$objPHPExcel);
		 
	 }
	 public function actionExportgspword(){
		
		 $ci  = new CDbCriteria();
		 if(!empty($_GET) && (count($_GET) == 4)){
		  foreach($_GET as $key => $value){
			  if($value == '')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('stuinfo');
		 }
		 $ci->addCondition('rights = 1');
		 $num = User::model()->count($ci);
		 $users  = User::model()->findAll($ci);
		 
		
		Yii::import('application.extensions.phpWord.*');
        require_once 'Autoloader.php';
        \PhpOffice\PhpWord\Autoloader::register();
		$phpWord = new \PhpOffice\PhpWord\PhpWord();
		$styleTable = array('borderSize' => 8, 'borderColor' => '000000', 'cellMargin' => 80);
		$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '000000', 'bgColor' => '66BBFF');
		$styleCell = array('valign' => 'center');
		$fontStyle = array('bold' => true, 'align' => 'center');
		$phpWord->addTableStyle('GSP', $styleTable);
		$phpWord->addFontStyle('header',array('size' => 22, 'bold' => true,'name'=>'Times New Roman'));
		
		$section = $phpWord->addSection();
		
		foreach($users as $u){
			
			$headerTextRun = $section->addTextRun(array('align'=>'center'));
			$headerTextRun->addText('教师教育学院gsp素质拓展成绩表','header');
		    
			$section->addTextBreak(1);
			$nameTextRun = $section->addTextRun();
			 if($u->stuinfo){
				     $realName = $u->stuinfo->realName;
					 $grade = $u->stuinfo->grade;
					 $classRoom = $u->stuinfo->classRoom;
					 $major = $u->stuinfo->major; 
				    
			 }else{
				     $realName = '未填写';
					 $grade = '未填写';
					 $classRoom = '未填写';
					 $major = '未填写'; 
				 
			 }
			$nameTextRun->addText('姓名:'.$realName.'     班级:'.$classRoom.'   年级:'.$grade.'          专业:'.$major.'         学号：'.$u->username);
			
			$table = $section->addTable('GSP');
			
			$table->addRow(400);
			$table->addCell(1500, $styleCell)->addText('拓展平台', $fontStyle);
			$table->addCell(1500, $styleCell)->addText('能力模块', $fontStyle);
			$table->addCell(1500, $styleCell)->addText('参加项目', $fontStyle);
			$table->addCell(1000, $styleCell)->addText('项目级别', $fontStyle);
			$table->addCell(1500, $styleCell)->addText('等级或获奖情况', $fontStyle);
			$table->addCell(1000, $styleCell)->addText('参加时间', $fontStyle);
			$table->addCell(1000, $styleCell)->addText('获得学分', $fontStyle);
			
			 
			 $g = 0;
			 $ss = 0;
			 $p = 0;
			 $q = 0;
			 $stuGsps = Stugspitem::model()->findAll('uId = :u',array(':u'=>$u->uId));
			 foreach($stuGsps as $s){
				 if($s->condition == '3'){
				     
					$table->addRow(400);
					$table->addCell(1500)->addText($s->plateform);
					$table->addCell(1500)->addText($s->module);
					$table->addCell(1500)->addText($s->name);
					$table->addCell(1000)->addText($s->level);
					$table->addCell(1500)->addText($s->prize);
					$table->addCell(1000)->addText($s->attendtime);
					$table->addCell(1000)->addText($s->credit);
					
					switch($s->module){
						case 'G':$g+=$s->credit;break;
						case 'S':$ss+=$s->credit;break;
						case 'P':$p+=$s->credit;break;
						case '其他':$q+=$s->credit;break;
						
					}
				 }
			 }
			
			
			$section->addTextBreak(1);
			$statisticTextRun = $section->addTextRun();
			$statisticTextRun->addText('小计：');
			$section->addTextBreak(1);
			
			$table = $section->addTable('GSP');
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('能力模块', $fontStyle);
			$table->addCell(3000, $styleCell)->addText('学分小计', $fontStyle);
			$table->addCell(3000, $styleCell)->addText('审核', $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('G', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($g, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('S', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($ss, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('P', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($p, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('其他', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($q, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
		    $table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('合计', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($q+$g+$ss+$p, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
				//落款
			        $section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$luokuanTextRun1 = $section->addTextRun(array('align'=>'right','bold'=>true));
					$luokuanTextRun1->addText('重庆第二师范学院教师教育学院');
					$section->addTextBreak(1);
					$luokuanTextRun2 = $section->addTextRun(array('align'=>'right','bold'=>true));
					$luokuanTextRun2->addText(date('Y-m-d'));
			$section->addPageBreak();
			
		}
	   $this->downloadWord(date('Y-m-d').'GSP导出-'.$num,$phpWord);
	 }
	 
	  public function actionExportinteword(){
		
		 $ci  = new CDbCriteria();
		 if(!empty($_GET) && (count($_GET) == 4)){
		  foreach($_GET as $key => $value){
			  if($value == '')
				  continue;
			  if($key == 'stuNumber'){
				  $ci->params[':s'] = $_GET['stuNumber'];
				  $ci->addCondition('username = :s');		  
			  }else{
			   $p = ':'.substr($key,0,1);	  
			   $ci->params[$p] = $value;
               $ci->addCondition('stuinfo.'.$key.' = '.$p);  
			  }
			  
		  }
		  $ci->with = array('stuinfo');
		 }
		 
		 $ci->addCondition('rights = 1');
		 $num = User::model()->count($ci);
		 $users  = User::model()->findAll($ci);
		 
		
		Yii::import('application.extensions.phpWord.*');
        require_once 'Autoloader.php';
        \PhpOffice\PhpWord\Autoloader::register();
		$phpWord = new \PhpOffice\PhpWord\PhpWord();
		$styleTable = array('borderSize' => 8, 'borderColor' => '000000', 'cellMargin' => 80);
		$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '000000', 'bgColor' => '66BBFF');
		$styleCell = array('valign' => 'center');
		$fontStyle = array('bold' => true, 'align' => 'center');
		$phpWord->addTableStyle('GSP', $styleTable);
		$phpWord->addFontStyle('header',array('size' => 22, 'bold' => true,'name'=>'Times New Roman'));
		
		$section = $phpWord->addSection();
		
		foreach($users as $u){
			
			$headerTextRun = $section->addTextRun(array('align'=>'center'));
			$headerTextRun->addText('教师教育学院综合素质拓展成绩表','header');
		    
			$section->addTextBreak(1);
			$nameTextRun = $section->addTextRun();
			 if($u->stuinfo){
				     $realName = $u->stuinfo->realName;
					 $grade = $u->stuinfo->grade;
					 $classRoom = $u->stuinfo->classRoom;
					 $major = $u->stuinfo->major; 
				    
			 }else{
				     $realName = '未填写';
					 $grade = '未填写';
					 $classRoom = '未填写';
					 $major = '未填写'; 
				 
			 }
			$nameTextRun->addText('姓名:'.$realName.'     班级:'.$classRoom.'   年级:'.$grade.'          专业:'.$major.'         学号：'.$u->username);
			
			$table = $section->addTable('GSP');
			
			$table->addRow(400);
			$table->addCell(2000, $styleCell)->addText('模块', $fontStyle);
			$table->addCell(2000, $styleCell)->addText('主要内容', $fontStyle);
			$table->addCell(1500, $styleCell)->addText('时间', $fontStyle);
			$table->addCell(2000, $styleCell)->addText('项目名称', $fontStyle);
			$table->addCell(1500, $styleCell)->addText('获得学分', $fontStyle);
			
			 $yc = 0;
			 $qs = 0;
			 $sh = 0;
			 $zy = 0;
			 $stuIntes = Stuinteitem::model()->findAll('uId = :u',array(':u'=>$u->uId));
			 foreach($stuIntes as $s){
				 if($s->condition == '3'){
					
					$table->addRow(400);
					$table->addCell(2000, $styleCell)->addText($s->module, $fontStyle);
					$table->addCell(2000, $styleCell)->addText($s->content, $fontStyle);
					$table->addCell(1500, $styleCell)->addText($s->term, $fontStyle);
					$table->addCell(2000, $styleCell)->addText($s->name, $fontStyle);
					$table->addCell(1500, $styleCell)->addText($s->credit, $fontStyle);
					
					switch($s->module){
						case '养成教育':$yc+=$s->credit;break;
						case '情商培养':$qs+=$s->credit;break;
						case '社会实践':$sh+=$s->credit;break;
						case '专业应用':$zy+=$s->credit;break;
						
					}
				 }
			 }
			
			
			$section->addTextBreak(1);
			$statisticTextRun = $section->addTextRun();
			$statisticTextRun->addText('小计：');
			$section->addTextBreak(1);
			
			$table = $section->addTable('GSP');
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('能力模块', $fontStyle);
			$table->addCell(3000, $styleCell)->addText('学分小计', $fontStyle);
			$table->addCell(3000, $styleCell)->addText('审核', $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('养成教育', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($yc, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('情商培养', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($qs, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('社会实践', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($sh, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('专业应用', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($zy, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			$table->addRow(400);
			$table->addCell(3000, $styleCell)->addText('合计', $fontStyle);
			$table->addCell(3000, $styleCell)->addText($zy+$sh+$qs+$yc, $fontStyle);
			$table->addCell(3000, $styleCell)->addText("", $fontStyle);
			
			//落款
			        $section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$section->addTextBreak(1);
					$luokuanTextRun1 = $section->addTextRun(array('align'=>'right','bold'=>true));
					$luokuanTextRun1->addText('重庆第二师范学院教师教育学院');
					$section->addTextBreak(1);
					$luokuanTextRun2 = $section->addTextRun(array('align'=>'right','bold'=>true));
					$luokuanTextRun2->addText(date('Y-m-d'));
			$section->addPageBreak();
			
		}
	    $this->downloadWord(date('Y-m-d').'综合素质导出-'.$num,$phpWord);
	 }
}
?>